/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

/**
 * @param {string} url
 * @returns {Boolean}
 */
export function validURL(url) {
  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return reg.test(url)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validLowerCase(str) {
  const reg = /^[a-z]+$/
  return reg.test(str)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUpperCase(str) {
  const reg = /^[A-Z]+$/
  return reg.test(str)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validAlphabets(str) {
  const reg = /^[A-Za-z]+$/
  return reg.test(str)
}

/**
 * @param {string} email
 * @returns {Boolean}
 */
export function validEmail(email) {
  const reg = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
  return reg.test(email)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function isString(str) {
  if (typeof str === 'string' || str instanceof String) {
    return true
  }
  return false
}

/**
 * @param {Array} arg
 * @returns {Boolean}
 */
export function isArray(arg) {
  if (typeof Array.isArray === 'undefined') {
    return Object.prototype.toString.call(arg) === '[object Array]'
  }
  return Array.isArray(arg)
}



/**
 * 是否为正确的证件号码
 * @param {certType} 证件类型，01省份证,02军官证,03港澳台身份证,04华侨身份证（无身份证者可填护照号）,05外籍护照
 */
export function isValidateCertNo(no,certType){
  var reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|x|X)$/; //省份证  
  var reg2 =/^[0-9]{8}$/ ; //军官证
  var reg3 = /^([0-9]{8}|[0-9]{10})$/; //台胞证
  var reg4 = /^[a-zA-Z0-9]{6,10}$/ ; //港澳通行证
  var reg5 = /^((\s?[A-Za-z])|([A-Za-z]{2}))\d{6}((\([0−9aA]\))|(\([0-9aA]\)))$/ ; //香港身份证
  var reg6 = /^[1|5|7][0-9]{6}\([0-9Aa]\)/ ; //澳门身份证
  var reg7 = /^[A-KM-QT-XZ]{1}[0-9]{9}$/ ; //台湾身份证
  var reg8 = /^[a-zA-Z0-9]{5,17}$/; //护照
  var reg9 = /^[1-9]d{5}[1-9]d{3}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}(d|x|X)$/; //驾照



  if(certType == '01'){
    return reg.test(no);
  }

  if(certType == '02'){
    return reg2.test(no);
  }

  if(certType == '03'){
    return reg3.test(no) || reg4.test(no) || reg5.test(no) || reg6.test(no) || reg7.test(no)
  }

  if(certType == '04'){
    return reg.test(no) || reg8.test(no);
  }

  
  if(certType == '05'){
    return  reg8.test(no);
  }
 
}

export function isCellphone(val){
 // var reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9]|19[0-9])\d{8}$/ ;
 // return reg.test(val)

  if(val.length == 11){
    return true;
  }else{
    return false;
  }

}

export function isEmail(val){
  var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  return reg.test(val);
}

export const inputRequire = { required: true, message: '不能为空', trigger: 'blur'};
export const selectRequire = { required: true, message: '不能为空', trigger: 'change'};